package org.mountainpunch.ds.sparsematrix;

/**
 *
 * @author siddharth
 */
final public class MatrixEntry <T> implements Comparable<MatrixEntry> {

  private int _row;
  private int _col;
  private T _value;

  public MatrixEntry() {
    _row = -1;
    _col = -1;
  }

  public MatrixEntry(int row, int col, T value) {
    _row = row ;
    _col = col ;
    _value = value;
  }

  public int getRow() {
    return _row;
  }

  public int getCol() {
    return _col;
  }

  public T getValue() {
    return _value;
  }

  public void setRow(int row) {
    _row = row;
  }

  public void setCol(int col) {
    _col = col;
  }

  public void setValue(T value) {
    _value = value;
  }

  public void setData(int row, int col, T value) {
    _row = row;
    _col = col;
    _value = value;
  }

  @Override
  public int compareTo(MatrixEntry that) {
    if(_row < that.getRow() || _col < that.getCol()) {
      return -1 ;
    } else if(_row > that.getRow() || _col > that.getCol()) {
      return 1 ;
    }
    
    //row and col are equal.
    return 0;
  }

  @Override
  public boolean equals(Object obj) {
    if(obj instanceof MatrixEntry) {
      MatrixEntry entry = (MatrixEntry)obj ;
      return _row == entry.getRow() && _col == entry.getCol() ;
    }

    throw new IllegalArgumentException("Invalid equality comparison of MatrixEntry");
  }

  @Override
  public int hashCode() {
    int hash = 7;
    hash = 41 * hash + this._row;
    hash = 41 * hash + this._col;
    hash = 41 * hash + (this._value != null ? this._value.hashCode() : 0);
    return hash;
  }
}
